package com.module.content.helper

import com.allen.base.utils.ViewUtils

/**
 * author : Allen
 * date   : 2020/08/21
 * time   : 9:25
 * desc   :
 */
object ImageCalculateHelper {

    data class ImageSize(val width: Int, val height: Int)

    /**
     * 计算单张大图显示宽高
     */
    fun getImageSize(array: List<Int>?, size: Int = 1, original: Boolean = false): ImageSize? {
        if (array == null || array.size < 2) {
            return null
        }
        val screenWidth = ViewUtils.getScreenWidth()

        val imageWidth = array[0]
        val imageHeight = array[1]
        if (original) {
            return ImageSize(imageWidth, imageHeight)
        }

        val margin = ViewUtils.dp2px(5) * (size - 1)
        val resultWidth = screenWidth - ViewUtils.dp2px(24) - margin
        //缩放比例
        val zoom = resultWidth / size / imageWidth.toFloat()
        return ImageSize((imageWidth * zoom).toInt(), (imageHeight * zoom).toInt())
    }
}